<layout name="page" />
<block name="content">
	<input type="hidden" name="ajax" id="ajax" value="1">
	{:widget('page_header/simple',array('name'=>'群组管理'))}
	<div class="operate-panel">
		<i class="mid"></i>
		<a class="btn btn-normal" onclick="add()" >新增</a>
		<a class="btn btn-normal" onclick="save()">保存</a>
		<i class="split"></i>
		<a onclick="del()"class="btn btn-del">删除</a>
	</div>
	<div class="x1 sub box">
		<div class="w88 m100" style="max-height:500px;overflow-y: auto;">
			<div class="table">
				<ul>
					<li class="thead">
						<span class="w10 x1">名称</span>
						<span class="w10">是否公开</span>
						<span class="w10">状态</span>
						<span class="w10">操作</span>
					</li>
					<foreach name="list" val="data">
						<li class="tbody" data="{$data.id}">
							<span class="click w10 x1">{$data.name}</span>
							<span class="click w10">{$data.is_public}</span>
							<span class="click w10">{$data.is_del}</span>
							<span class="w10"><a href="{:url('user',array('id'=>$data['id']))}">管理成员</a></span>
						</li>
					</foreach>
				</ul>
			</div>
		</div>
		<div style="width:16px;"></div>
		<div class="x1 frame m100" style="height:350px;">
			<form id="form_data" name="form_data" method="post" style="width:100%;">
				<input type="hidden" name="id" id="id">
				<input type="hidden" name="ajax" id="ajax" value="0">
				<input type="hidden" name="opmode" id="opmode" value="">
				<div class="col-12 box">
					<label class="input-label" for="name">名称*：</label>
					<input class="input w19" type="text" id="name" name="name" check="required" info="请输入名称">
				</div>
				<div class="col-12 box">
					<label class="input-label" for="sort">排序：</label>
					<input class="input w19" type="text" id="sort" name="sort" >
				</div>
				<div class="col-12 box">
					<label class="input-label" for="is_public">是否公开*：</label>
					<select class="select w10" name="is_public" id="is_public">
						<option  value="0">私有</option>
						<option value="1">公开</option>
					</select>
					<i class="icon"></i>
				</div>
				<div class="col-12 box">
					<label class="input-label" for="is_del">状态*：</label>
					<select  class="select w10" name="is_del" id="is_del">
						<option  value="0">启用</option>
						<option value="1">禁用</option>
					</select>
				</div>
				<div class="col-12 box">
					<label class="input-label" for="remark">备注*：</label>
					<textarea class="textarea" name="remark" id="remark" rows="5" class="col-xs-12" ></textarea>
				</div>
			</form>
		</div>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		layui.use(['global'], function() {
			var fn = {
				add : function() {
					winopen("{:url('add')}", 560, 470);
				},
				save : function() {
					send_form("form_data", "{:url('save')}", "{:url('index')}", function(ret) {
						if (ret.status) {
							layer.msg(ret.info, {
								time : 1200
							}, function() {
								location.href = "{:url('index')}";
							});
						} else {
							layer.msg(ret.info);
							return false;
						}
					});
				},
				del : function() {
					if ($(".table li.active").length == 0) {
						layer.msg('请选择要删除的数据');
						return false;
					}
					//信息框-例2
					layer.msg('确定要删除吗?', {
						time : 0,
						btn : ['确定', '取消'],
						yes : function(index) {
							var vars = $("#form_data").serialize();
							send_ajax("{:url('del')}", vars, function(ret) {
								if (ret.status) {
									layer.msg(ret.info, {
										time : 1200
									}, function() {
										location.reload(true);
									});
								}
							});
						},
						no : function(index) {
							layer.close(index);
						}
					});
				}
			};
			win_exp(fn);

			set_return_url(null);

			$(".table span.click").click(function() {
				$(".table li.active").removeClass("active");
				$li = $(this).parents('li');
				$li.addClass("active");
				var vars = {};
				vars.id = $li.attr('data');
				send_ajax("{:url('read')}", vars, function(ret) {
					show_data(ret);
				});
				return false;
			});

			function show_data(ret) {
				for (var s in ret.data) {
					set_val(s, ret.data[s]);
				}
				$("#opmode").val("edit");
			};
		});
	</script>
</block>